package springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DiscoverController {
    @Autowired
    private DiscoveryClient client;

    @RequestMapping("/dept/discovery")
    public Object discover(){
        List<String> services = client.getServices();
        System.out.println("discovery=> services"+services);
        List<ServiceInstance> instances = client.getInstances("SPRINGCLOUD-PROVIDER-DEPT");

        for (ServiceInstance instance : instances){
            System.out.println(instance.getHost()+":"+instance.getPort());
            System.out.println(instance.getUri());
            System.out.println(instance.getServiceId());
        }
        return this.client;

    }
}
